#include "Queue.h"
void QueueInit(Queue* pd)
{
	assert(pd);
	pd->head = NULL;
	pd->tail = NULL;
	pd->size=0;
}
void Queuepush(Queue* pd, Qdatetype x)
{
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	assert(newnode);
	newnode->date = x;
	newnode->next = NULL;
	if (pd->head == NULL)
	{
		pd->head = pd->tail = newnode;
	}
	else
	{
		pd->tail->next = newnode;
		pd->tail = newnode;
	}
	pd->size++;
}
void Queuedestroy(Queue* pd)
{
	assert(pd);
	QNode* cur=pd->head;
	while (cur)
	{
		QNode* next = cur->next;
		free(cur);
		cur = next;
	}
	pd->head = pd->tail = NULL;
	pd->size = 0;
}
//
void Queuepop(Queue * pq)
	{
		assert(pq);
		assert(pq->head != NULL);

		
		if (pq->head->next == NULL)
		{
			free(pq->head);
			pq->head = pq->tail = NULL;
		}
		else
		{
			QNode* next = pq->head->next;
			free(pq->head);
			pq->head = next;
		}

		pq->size--;
	}
Qdatetype Queuesize(Queue* pd)
{
	assert(pd);
	return pd->size;
}
bool Queueempty(Queue* pd)
{
	assert(pd);
	return pd->size == 0;

}
Qdatetype Queuefront(Queue* pd)
{
	assert(pd);
	assert(!Queueempty(pd));
	return pd->head->date;
}
Qdatetype Queueback(Queue* pd)
{
	assert(pd);
	return pd->tail->date;
}
